package com.hanlp.top_interview_150.数组;

/**
 * 80. 删除有序数组中的重复项 II
 */
public class A04 {
    public static void main(String[] args) {

    }

    public static int removeDuplicates(int[] nums) {
        if(nums.length < 2){
            return nums.length;
        }
        int count = 0;
        for (int i = 1; i < nums.length; i++) {
            if(nums[count] != nums[i]){
                nums[++count] = nums[i];
            }else{
                nums[++count] = nums[i];
                for (; i < nums.length; i++) {
                    if(nums[count] != nums[i]){
                        nums[++count] = nums[i];
                        break;
                    }
                }
            }
        }
        return count+1;
    }


}
